#include <Kharlia/Engine/Common.h>
#include <Kharlia/Engine/Player.h>

namespace kharlia { namespace engine {

CPlayer::CPlayer(PyObject* self, bool isLocal):
    CObject(self),
    mIsLocal(isLocal),
    mRMConnection(nullptr)
    {}

CPlayer::~CPlayer() {}

KH_BEGIN_GC(CPlayer)
    KH_GC_TPTR(thisx->mActor)
KH_END_GC()

CLocalPlayer::CLocalPlayer(PyObject* self):
    CPlayer(self, true)
    {
    }

CLocalPlayer::~CLocalPlayer() {}

void CLocalPlayer::OnKeyDown(ui::Key::Scan keycode) {
    call_method<void>(mSelf, "OnKeyDown", keycode);
}

KH_NO_GC(CLocalPlayer)

void _InitPlayerClasses() {
    using namespace py;

    class_<CPlayer, bases<core::CObject>, boost::noncopyable>
        ("CPlayerBase", init<>())
        .def(init<bool>())
        .def_readonly("IsLocal", &CPlayer::mIsLocal)
        .add_property("Actor", &CPlayer::GetActor, &CPlayer::SetActor)
        ;

    KH_IMPL_GC(CPlayer);
    RegisterPtrConverter<CPlayer>();

    class_<CLocalPlayer, bases<CPlayer>, boost::noncopyable>
        ("CLocalPlayerBase", init<>())
        ;

    KH_IMPL_GC(CLocalPlayer);
    RegisterPtrConverter<CLocalPlayer>();
}

}}